package net.zjitc.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/24 11:07
 * 接收键盘用户名
 * 将该用户删除
 */
public class PreparedStatementTest1 {
    public static void main(String[] args) {
        Scanner scannerInt = new Scanner(System.in);
        Scanner scannerString = new Scanner(System.in);
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/lgy";
            String user = "root";
            String password = "123456";
            conn = DriverManager.getConnection(url, user, password);
            String sql = "DELETE FROM USER WHERE NAME=?";
            pstmt = conn.prepareStatement(sql);
            System.out.println("请输入要删除的用户名：");
            String name = scannerString.nextLine();
            pstmt.setString(1, name);
            int s = pstmt.executeUpdate();
            System.out.println("影响了" + s + "行");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
